package com.chentongwei.spring.annotation.component.config;

import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;

import java.io.IOException;

/**
 * @Description:
 * @author TongWei.Chen 2018-07-02 11:01:52
 * @Project spring-annonation
 */
public class MyTypeFilter implements TypeFilter {

    /**
     * @param metadataReader：读取到的当前正在扫描的类的信息
     * @param metadataReaderFactory：获取到其他任何类信息
     * @return
     * @throws IOException
     */
    @Override
    public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {

        /**
         * 获取当前类注解信息
         */
        AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();

        /**
         * 获取当前类的类信息
         */
        ClassMetadata classMetadata = metadataReader.getClassMetadata();

        /**
         * 获取当前类资源信息，比如类路径等资源。
         */
        Resource resource = metadataReader.getResource();

        String className = classMetadata.getClassName();
        System.out.println("className:---->" + className);
        if (className.contains("er")) {
            return true;
        }
        return false;
    }
}
